// Copyright 2009 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: Jeff Stewart
//
// Displays a progress bar as tests run.

#ifndef POPDIAG_UI_PROGRESSSCREEN_H__
#define POPDIAG_UI_PROGRESSSCREEN_H__

#include <QtGui/QWidget>
#include <QtGui/QProgressBar>
#include <QtGui/QtGui>

#include "probes/executive.h"
#include "ui/browser.h"
#include "util/common.h"

namespace popdiag {

class ProgressScreen : public QWizardPage {
  Q_OBJECT
 public:
  // Create a progress screen owned by app.
  explicit ProgressScreen(QWidget *app);
  virtual ~ProgressScreen();

  // Setup all the UI elements.
  virtual void SetupUI();

  // Overridden from QWizardPage.  Called before the page is displayed.
  virtual void initializePage();

  // Overridden from QWizardPage.  Called before the page is undisplayed.
  virtual void cleanupPage();

  // Overridden from QWizardPage.  Determines if the next button is active.
  virtual bool isComplete() const;

 signals:
  // Emitted when we write a report to local disk.
  void ReportWrittenToDesktop(const QString &path);

  // Emitted when we're done.  Passes the results to the next wizard page.
  void TestsComplete(const ProbeSet::Storage &results);

  public slots:

  // Progress has been made.  Update the progress display.
  void OnProgressMade(int progress_made, int estimated_total);

  // Executive is done running tests
  void OnExecutiveDone();

  // Here is the diagnostic blurb from the configuration checker.  Note it for
  // the report.
  void ClientConfigLogs(const QString &logs);

  // Write out a report to the desktop:
  void WriteReportToDesktop();

 private:
  void SetComplete(bool newval);
  ProbeSet *SetupProbes();
  void PopulateProbes(ProbeSet *probes);

  bool complete_;
  QProgressBar *progress_;
  Browser      *prolog_;
  QString       config_log_;
  scoped_ptr<Executive> executive_;
  DISALLOW_EVIL_CONSTRUCTORS(ProgressScreen);
};

}  // namespace popdiag

#endif  // POPDIAG_UI_PROGRESSSCREEN_H__
